package cn.jd.basic.controller;

import cn.jd.basic.dto.*;
import cn.jd.basic.service.VerifyCodeService;
import cn.jd.basic.util.AjaxResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private VerifyCodeService verifyCodeService;
 /*/verifyCode/accountuser"*/

    @PostMapping("/accountuser")
    public AjaxResult accountuser(@RequestBody @Valid AccountUserDto dto){
        verifyCodeService.accountuser(dto);
        return AjaxResult.me().success() ;
    }
    /**
     * mail   邮箱注册数据保存接口
     * @param
     * @return
     */

    @PostMapping("/register/mail")
    public AjaxResult mail(@RequestBody @Valid RegisterMailDto registerMailDto) {

        verifyCodeService.registermail(registerMailDto);
        return AjaxResult.me().success();
    }

   /* /verifyCode/image/   获取图片验证码*/
    @GetMapping("/image/{key}")
    public AjaxResult image(@PathVariable String key){

        String image = verifyCodeService.image(key);

        return AjaxResult.me().success(image) ;
    }
    /**
     * 邮箱验证码
     * /verifyCode/mailsmsCode"
     */
    @PostMapping("/mailsmsCode")
    public AjaxResult mailsmsCode(@RequestBody @Valid MailDto mailDto){
        verifyCodeService.mailsmsCode(mailDto);
        return AjaxResult.me().success() ;
    }
    /**
     * 手机验证码
     */

    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid GetCodePhone getCodePhone){

        verifyCodeService.smsCode(getCodePhone);
        return AjaxResult.me().success() ;
    }
    /**
     * user/register/phone
     * 用户手机注册
     */
    @PostMapping("/register/phone")
    public AjaxResult json(@RequestBody @Valid RegisteredDto registeredDto) {
        System.out.println(registeredDto.getSmsCode()+"code");
        verifyCodeService.registerPhone(registeredDto);
        return AjaxResult.me().success();
    }
}
